﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Common.eConnect.Communicator.DynamicProxy;

namespace Common.eConnect.Communicator
{
    public class eConnectCommunicator
    {
        internal readonly string DynamiceConectWcfURI = "http://localhost/Microsoft/Dynamics/GP/eConnect/mex";

        private DynamicProxyFactory factory = null;

        public eConnectCommunicator()
        {
            factory = new DynamicProxyFactory(DynamiceConectWcfURI);
        }

        public bool CreateEntity(string connectionString, string xml)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (bool)DynCreateEntity.CallMethod("CreateEntity", connectionString, xml);
        }

        public string CreateTransactionEntity(string connectionString, string xml)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (string)DynCreateEntity.CallMethod("CreateTransactionEntity", connectionString, xml);
        }

        public bool DeleteEntity(string connectionString, string xml)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (bool)DynCreateEntity.CallMethod("DeleteEntity", connectionString, xml);
        }

        public bool DeleteTransactionEntity(string connectionString, string xml)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (bool)DynCreateEntity.CallMethod("DeleteTransactionEntity", connectionString, xml);
        }

        public string GetEntity(string connectionString, string xml)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (string)DynCreateEntity.CallMethod("GetEntity", connectionString, xml);
        }

        public string GetNextGLJournalEntryNumber(object incdec, string databaseConnectionString)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (string)DynCreateEntity.CallMethod("GetNextGLJournalEntryNumber", incdec, databaseConnectionString);
        }

        public string GetNextIVNumber(object incdec, object documentType, string databaseConnectionString)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (string)DynCreateEntity.CallMethod("GetNextGLJournalEntryNumber", incdec, documentType, databaseConnectionString);
        }

        public string GetNextPONumber(object incdec, string databaseConnectionString)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (string)DynCreateEntity.CallMethod("GetNextPONumber", incdec, databaseConnectionString);
        }

        public string GetNextPOPReceiptNumber(object incdec, string databaseConnectionString)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (string)DynCreateEntity.CallMethod("GetNextPOPReceiptNumber", incdec, databaseConnectionString);
        }

        public string GetNextRMNumber(object incdec, object documentType, string databaseConnectionString)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (string)DynCreateEntity.CallMethod("GetNextRMNumber", incdec, documentType, databaseConnectionString);
        }

        public string GetNextSOPNumber(object incdec, object documentType, string databaseConnectionString)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (string)DynCreateEntity.CallMethod("GetNextSOPNumber", incdec, documentType, databaseConnectionString);
        }

        public string GetPMNextVoucherNumber(object incdec, string databaseConnectionString)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (string)DynCreateEntity.CallMethod("GetPMNextVoucherNumber", incdec, databaseConnectionString);
        }

        public string RollBackDocuments(object[] documentNumberCollection, string databaseConnectionString)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (string)DynCreateEntity.CallMethod("RollBackDocuments", documentNumberCollection, databaseConnectionString);
        }

        public bool UpdateEntity(string connectionString, string xml)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (bool)DynCreateEntity.CallMethod("UpdateEntity", connectionString, xml);
        }

        public bool UpdateTransactionEntity(string connectionString, string xml)
        {
            DynamicProxy.DynamicProxy DynCreateEntity = factory.CreateProxy("eConnect");

            return (bool)DynCreateEntity.CallMethod("UpdateTransactionEntity", connectionString, xml);
        }

        /*
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.CreateEntity
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.CreateTransactionEntity
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.DeleteEntity
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.DeleteTransactionEntity
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.GetEntity
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.GetNextGLJournalEntryNumber
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.GetNextIVNumber
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.GetNextPONumber
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.GetNextPOPReceiptNumber
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.GetNextRMNumber
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.GetNextSOPNumber
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.GetPMNextVoucherNumber
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.RollBackDocuments
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.UpdateEntity
         * SpencerForrestSOPImportToeConnect.SpencerForrestSOPImportToeConnect.eConnect.UpdateTransactionEntity
        */
    }
}
